/**
******************************************************************************
* @file    delay.h
* @author  lilianfu <lilianfu@msn.com>
* @version V1.0.0
* @date    18-Ocoober-2016
* @brief   systick timer
******************************************************************************
* @attention
* Class declaration for systick timer for delay function
*
******************************************************************************
*/
#ifndef __USB_KEYBOARD_H
#define __USB_KEYBOARD_H
#ifdef __cplusplus
extern "C" {
#endif
#include "stm32f10x.h"
#include "stm32f10x_gpio.h"
	/* Keys */
#define Keys_Reserved_No_Event_Indicated                      0x00
#define KeyBoard_ErrorRollOver                                0x01
#define KeyBoard_PostFail                                     0x02
#define KeyBoard_ErrorUndfined                                0x03
#define KeyBoard_A                                            0x04
#define KeyBoard_B                                            0x05
#define KeyBoard_C                                            0x06
#define KeyBoard_D                                            0x07
#define KeyBoard_E                                            0x08
#define KeyBoard_F                                            0x09
#define KeyBoard_G                                            0x0A
#define KeyBoard_H                                            0x0B
#define KeyBoard_I                                            0x0C
#define KeyBoard_J                                            0x0D
#define KeyBoard_K                                            0x0E
#define KeyBoard_L                                            0x0F
#define KeyBoard_M                                            0x10
#define KeyBoard_N                                            0x11
#define KeyBoard_O                                            0x12
#define KeyBoard_P                                            0x13
#define KeyBoard_Q                                            0x14
#define KeyBoard_R                                            0x15
#define KeyBoard_S                                            0x16
#define KeyBoard_T                                            0x17
#define KeyBoard_U                                            0x18
#define KeyBoard_V                                            0x19
#define KeyBoard_W                                            0x1A
#define KeyBoard_X                                            0x1B
#define KeyBoard_Y                                            0x1C
#define KeyBoard_Z                                            0x1D
#define KeyBoard_D1                                           0x1E
#define KeyBoard_D2                                           0x1F
#define KeyBoard_D3                                           0x20
#define KeyBoard_D4                                           0x21
#define KeyBoard_D5                                           0x22
#define KeyBoard_D6                                           0x23
#define KeyBoard_D7                                           0x24
#define KeyBoard_D8                                           0x25
#define KeyBoard_D9                                           0x26
#define KeyBoard_D0                                           0x27
#define KeyBoard_Return_Enter                                 0x28
#define KeyBoard_Eacape                                       0x29
#define KeyBoard_Delete_Backspace                             0x2A
#define KeyBoard_Tab                                          0x2B
#define KeyBoard_Spacebar                                     0x2C
#define KeyBoard_Dash_And_Underscore                          0x2D /* - and _*/
#define KeyBoard_Plus_And_Equals                              0x2E /* = and + */
#define KeyBoard_OpenSquareBracket_And_OpenBrace              0x2F /* [ and { */
#define KeyBoard_CloseSquareBracket_And_CloseBrace            0x30 /* ] and } */
#define KeyBoard_BackSlash_And_Bar                            0x31 /* \ and | */
#define KeyBoard_Hash_And_Tilde                               0x32 /* # and ~ */   
#define KeyBoard_SemiColon_And_Colon                          0x33 /* ; and : */
#define KeyBoard_SigleQuote_And_DoubleQuote                   0x34 /* ' and " */
#define KeyBoard_Grave_Acceent_And_Tilde                      0x35
#define KeyBoard_Comma_And_Less                               0x36 /* , and < */
#define KeyBoard_Dot_And_Greater                              0x37 /* . and > */
#define KeyBoard_Slash_And_Question                           0x38 /* / and ? */
#define KeyBoard_Caps_Lock                                    0x39
#define KeyBoard_F1                                           0x3A
#define KeyBoard_F2                                           0x3B
#define KeyBoard_F3                                           0x3C
#define KeyBoard_F4                                           0x3D
#define KeyBoard_F5                                           0x3E
#define KeyBoard_F6                                           0x3F
#define KeyBoard_F7                                           0x40
#define KeyBoard_F8                                           0x41
#define KeyBoard_F9                                           0x42
#define KeyBoard_F10                                          0x43
#define KeyBoard_F11                                          0x44
#define KeyBoard_F12                                          0x45
#define KeyBoard_PrinfScreen                                  0x46
#define KeyBoard_ScrollLock                                   0x47
#define KeyBoard_Pause                                        0x48
#define KeyBoard_Insert                                       0x49
#define KeyBoard_Home                                         0x4A
#define KeyBoard_PageUp                                       0x4B
#define KeyBoard_DeleteForward                                0x4C
#define KeyBoard_End                                          0x4D
#define KeyBoard_PageDown                                     0x4E
#define KeyBoard_RightArrow                                   0x4F
#define KeyBoard_LeftArrow                                    0x50
#define KeyBoard_DownArrow                                    0x51
#define KeyBoard_UpArrow                                      0x52
#define KeyPad_NumLock                                        0x53
#define KeyPad_Slash                                          0x54 /* / */
#define KeyPad_Star                                           0x55 /* * */
#define KeyPad_Dash                                           0x56 /* - */
#define KeyPad_Plus                                           0x57 /* + */
#define KeyPad_Enter                                          0x58
#define KeyPad_D1                                             0x59
#define KeyPad_D2                                             0x5A
#define KeyPad_D3                                             0x5B
#define KeyPad_D4                                             0x5C
#define KeyPad_D5                                             0x5D
#define KeyPad_D6                                             0x5E
#define KeyPad_D7                                             0x5F
#define KeyPad_D8                                             0x60
#define KeyPad_D9                                             0x61
#define KeyPad_D0                                             0x62
#define KeyBoard_Delete                                       0x63
#define KeyBoard_Non_US_Pipe_And_BackSlash                    0x64 /* | and \ */
//Uinx
#define KeyBoard_Application                                  0x65
//PC-Mac
#define KeyBoard_Power                                        0x66 /* Boot 4/101/104 */
//Boot 
//#define KeyPad_Equals                                         0x67 /* = */
//#define KeyBoard_F13                              0x68
//#define KeyBoard_F14                              0x69
//#define KeyBoard_F15                              0x6A
//#define KeyBoard_F16                              0x6B
//#define KeyBoard_F17                              0x6C
//#define KeyBoard_F18                              0x6D
//#define KeyBoard_F19                              0x6E
//#define KeyBoard_F20                              0x6F
//#define KeyBoard_F21                              0x70
//#define KeyBoard_F22                              0x71
//#define KeyBoard_F23                              0x72
//#define KeyBoard_F24                              0x73
//#define KeyBoard_Execute                          0x74
//#define KeyBoard_Help                             0x75
//#define KeyBoard_Menu                             0x76
//#define KeyBoard_Select                           0x77
//#define KeyBoard_Stop                             0x78
//#define KeyBoard_Again                            0x79
//#define KeyBoard_Undo                             0x7A
//#define KeyBoard_Cute                             0x7B
//#define KeyBoard_Copy                             0x7C
//#define KeyBoard_Past                             0x7D
//#define KeyBoard_Find                             0x7E
//#define KeyBoard_Mute                             0x7F
//#define KeyBoard_VolumeUp                         0x80
//#define KeyBoard_VolumeDown                       0x81
//#define KeyBoard_LockingCapsLock                  0x82
//#define KeyBoard_LockingNumLock                   0x83
//#define KeyBoard_LockingScrollLock                0x84
//#define KeyPad_Comma                              0x85
//#define KeyPad_EuqalSign                          0x86
//#define KeyBoard_International1                   0x87
//#define KeyBoard_International2                   0x88
//#define KeyBoard_International3                   0x89
//#define KeyBoard_International4                   0x8A
//#define KeyBoard_International5                   0x8B
//#define KeyBoard_International6                   0x8C
//#define KeyBoard_International7                   0x8D
//#define KeyBoard_International8                   0x8E
//#define KeyBoard_International9                   0x8F
//#define KeyBoard_Lang1                            0x90
//#define KeyBoard_Lang2                            0x91
//#define KeyBoard_Lang3                            0x92
//#define KeyBoard_Lang4                            0x93
//#define KeyBoard_Lang5                            0x94
//#define KeyBoard_Lang6                            0x95
//#define KeyBoard_Lang7                            0x96
//#define KeyBoard_Lang8                            0x97
//#define KeyBoard_Lang9                            0x98
//#define KeyBoard_AlternateErase                   0x99
//#define KeyBoard_SysReq_Attention                 0x9A
//#define KeyBoard_Cancel                           0x9B
//#define KeyBoard_Clear                            0x9C
//#define KeyBoard_Prior                            0x9D
//#define KeyBoard_Return                           0x9E
//#define KeyBoard_Separator                        0x9F
//#define KeyBoard_Out                              0xA0
//#define KeyBoard_Oper                             0xA1
//#define KeyBoard_Clear_Again                      0xA2
//#define KeyBoard_CrSel_Props                      0xA3
//#define KeyBoard_ExSel                            0xA4
///* 165-175 A5-AF Reaserved */
//#define KeyPad_00                                 0xB0
//#define KeyPad_000                                0xB1
//#define Keys_ThousandsSeparator                   0xB2
//#define Keys_DecimalSeparator                     0xB3
//#define Keys_CurrencyUint                         0xB4
//#define Keys_CurrencySub_Uint                     0xB5
//#define KeyPad_OpenBracket                        0xB6 /* ( */
//#define KeyPad_CloseBracket                       0xB7 /* ) */
//#define KeyPad_OpenBrace                          0xB8 /* { */
//#define KeyPad_CloseBrace                         0xB9 /* } */
//#define KeyPad_Tab                                0xBA
//#define KeyPad_Backspace                          0xBB
//#define KeyPad_A                                  0xBC
//#define KeyPad_B                                  0xBD
//#define KeyPad_C                                  0xBE
//#define KeyPad_D                                  0xBF
//#define KeyPad_E                                  0xC0
//#define KeyPad_F                                  0xC1
//#define KeyPad_XOR                                0xC2
//#define KeyPad_Caret                              0xC3 /* ^  */
//#define KeyPad_Modulus                            0xC4 /* %  */
//#define KeyPad_LeftAgnleBracket                   0xC5 /* <  */
//#define KeyPad_RightAgnleBracket                  0xC6 /* >  */
//#define KeyPad_Ampersand                          0xC7 /* &  */
//#define KeyPad_DoubleAmpersand                    0xC8 /* && */
//#define KeyPad_Pipe                               0xC9 /* |  */
//#define KeyPad_DoublePipe                         0xCA /* || */
//#define KeyPad_Colon                              0xCB /* :  */
//#define KeyPad_Hash                               0xCC /* #  */
//#define KeyPad_Space                              0xCD
//#define KeyPad_AT                                 0xCE /* @ */
//#define KeyPad_ExclamationMark                    0xCF /* ! */
//#define KeyPad_MemoryStore                        0xD0
//#define KeyPad_MemoryRecal                        0xD1
//#define KeyPad_MemoryClear                        0xD2
//#define KeyPad_MemoryAdd                          0xD3
//#define KeyPad_MemorySubtract                     0xD4
//#define KeyPad_MemoryMultiply                     0xD5
//#define KeyPad_MemoryDivide	                      0xD6
//#define KeyPad_Pluse_Minus	                      0xD7 /* +/- */
//#define KeyPad_Clear                              0xD8
//#define KeyPad_ClearEnter                         0xD9
//#define KeyPad_Binary                             0xDA
//#define KeyPad_Octal                              0xDB
//#define KeyPad_Decimal                            0xDC
//#define KeyPad_Hexadecimal                        0xDD
///* 222-223 DE-DF Reaerved */
#define KeyBoard_LeftControl                      0xE0
#define KeyBoard_LeftShift                        0xE1
#define KeyBoard_LeftAlt                          0xE2
#define KeyBoard_LeftGUI                          0xE3
#define KeyBoard_RightControl                     0xE4
#define KeyBoard_RightShift                       0xE5
#define KeyBoard_RightAlt                         0xE6
#define KeyBoard_RightGUI                         0xE7
/* 232-65535 E8-FFFF Reaerved */

/*
        CLO01  CLO02  CLO03  CLO04  CLO05  CLO06  CLO07  CLO08  CLO09  CLO10  CLO011
ROW01     A      B      C      D      E      F
ROW02     G      H      I      J      K      L
ROW03     M      N      O      P      Q      R
ROW04     S      T      U      V      W      X
ROW05     Y      Z      0      1      2      3
ROW06     4      5      6      7      8      9
ROW07   LSHIFT RSHIFT  UPARR  TAB    
ROW08   LCTRL  RCTRL   DOARR  ENTER
ROW09   LALT   RATL    LARR   BASP
ROW10   LGUI   RGUI    RARR   DELE
*/








/* .NET 
#define Keys_Nome 
#define Keys_LButtom 
#define Keys_RButtom 
#define Keys_Cancel 
#define Keys_MButtom
#define Keys_XButtom1
#define Keys_XButtom2
#define Keys_Back
#define Keys_Tab
#define Keys_Clean
#define Keys_Return
#define Keys_Enter
#define Keys_ShiftKey
#define Keys_ControlKey
#define Keys_Menu
#define Keys_Pause
#define Keys_Capital
#define Keys_CapsLock
#define Keys_KanaMode
#define Keys_HangueMode
#define Keys_HangulMode
#define Keys_JunjaMode
#define Keys_FinalMode
#define Keys_HanjaMode
#define Keys_KanjiMode
#define Keys_Ecape
#define Keys_IMEConvert
#define Keys_IMENonconvert
#define Keys_IMEAccept
#define Keys_IMEModeChange
#define Keys_Space
#define Keys_Frior
#define Keys_PageUp
#define Keys_Next
#define Keys_PageDown
#define Keys_End
#define Keys_Home
#define Keys_Left
#define Keys_Up
#define Keys_Right
#define Keys_Down
#define Keys_Select
#define Keys_Printf
#define Keys_Execute
#define Keys_Snapshot
#define Keys_PrintScreen
#define Keys_Insert
#define Keys_Delete
#define Keys_Help
#define Keys_D0
#define Keys_D1
#define Keys_D2
#define Keys_D3
#define Keys_D4
#define Keys_D5
#define Keys_D6
#define Keys_D7
#define Keys_D8
#define Keys_D9
#define Keys_A
#define Keys_B
#define Keys_C
#define Keys_D
#define Keys_E
#define Keys_F
#define Keys_G
#define Keys_H
#define Keys_I
#define Keys_J
#define Keys_K
#define Keys_L
#define Keys_M
#define Keys_O
#define Keys_P
#define Keys_Q
#define Keys_R
#define Keys_S
#define Keys_T
#define Keys_U
#define Keys_V
#define Keys_W
#define Keys_X
#define Keys_Y
#define Keys_Z
#define Keys_LWin
#define Keys_RWin
#define Keys_Apps
#define Keys_Sleep
#define Keys_NumPad0
#define Keys_Numpad1
#define Keys_NumPad2
#define Keys_NumPad3
#define Keys_NumPad4
#define Keys_NumPad5
#define Keys_NumPad6
#define Keys_NumPad7
#define Keys_NumPad8
#define Keys_NumPad9
#define Keys_Multiply
#define Keys_Add
#define Keys_Separator
#define Keys_Subtract
#define Keys_Decimal
#define Keys_Divide
#define Keys_F1
#define Keys_F2
#define Keys_F3
#define Keys_F4
#define Keys_F5
#define Keys_F6
#define Keys_F7
#define Keys_F8
#define Keys_F9
#define Keys_F10
#define Keys_F11
#define Keys_F12
#define Keys_F13
#define Keys_F14
#define Keys_F15
#define Keys_F16
#define Keys_F17
#define Keys_F18
#define Keys_F19
#define Keys_F20
#define Keys_F21
#define Keys_F22
#define Keys_F23
#define Keys_F24
#define Keys_NumLock
#define Keys_Scroll
#define Keys_LShiftKey
#define Keys_RShiftKey
#define Keys_LControlKey
#define Keys_RControlKey
#define Keys_LMenu
#define Keys_RMenu
#define Keys_BrowserBack
#define Keys_BrowserForward
#define Keys_BrswaerRefresh
#define Keys_BrowserStop
#define Keys_BrowserSearch
#define Keys_BrowserFavorites
#define Keys_BrowserHome
#define Keys_VolumeMute
#define Keys_VolumeDown
#define Keys_VolumeUp
#define Keys_MediaNextTrack
#define Keys_MediaPreviousTrack
#define Keys_MediaStop
#define Keys_MediaPlayPause
#define Keys_LaunchMail
#define Keys_SelectMedia
#define Keys_LaunchApplication1
#define Keys_LaunchApplication2
#define Keys_OemSemicolon
#define Keys_Oeml
#define Keys_Oemplus
#define Keys_Oemcomma
#define Keys_OemMinus
#define Keys_OemPeriod
#define Keys_OemQuestion
#define Keys_Oem2
#define Keys_Oemtilde
#define Keys_Oem3
#define Keys_OemOpenBrackets
#define Keys_Oem4
#define Keys_OemPipe
#define Keys_Oem5
#define Keys_OemCloseBrackets
#define Keys_Oem6
#define Keys_OemQuotes
#define Keys_Oem7
#define Keys_Oem8
#define Keys_OemBackslash
#define Keys_Oem102
#define Keys_ProcessKey
#define Keys_Packet
#define Keys_Attn
#define Keys_Crsel
#define Keys_Exsel
#define Keys_EraseEof
#define Keys_Play
#define Keys_Zoom
#define Keys_NoName
#define Keys_Pa1
#define Keys_OemClear
#define Keys_KeyCode
#define Keys_Shift
#define Keys_Control
#define Keys_Alt
*/
/* Key GPIO Mapping */
/* USBDP PA12 USBDM PA11, USART1TX PA9,USART1RX10 LED0 PA13 */
/* ASIX
    PC15 PC1 PC3 PA1 - PA3 PA5 PA7 PC5
	LEFT KEYBOARD 
	PC14 PC00 PC02 - PA00 PA02 PA04
	BUTTON
	PB09 PB07 PB05 - PB03 PC12 PC10
*/
#define COLUMN_LINE                    0x00
#define RCC_APB2Periph_COLUMN_GPIO    (RCC_APB2Periph_GPIOC|RCC_APB2Periph_GPIOC|RCC_APB2Periph_GPIOC)
/* RIGHT KEYBOARD COL */
#define COLUMN01_PORT                  GPIOC
#define COLUMN01_PIN                   GPIO_Pin_15
#define COLUMN02_PORT                  GPIOC
#define COLUMN02_PIN                   GPIO_Pin_1
#define COLUMN03_PORT                  GPIOC
#define COLUMN03_PIN                   GPIO_Pin_3
#define COLUMN04_PORT                  GPIOA
#define COLUMN04_PIN                   GPIO_Pin_1
/* LEFT KEYBOARD COL */
#define COLUMN05_PORT                  GPIOC
#define COLUMN05_PIN                   GPIO_Pin_14
#define COLUMN06_PORT                  GPIOC
#define COLUMN06_PIN                   GPIO_Pin_0
#define COLUMN07_PORT                  GPIOC
#define COLUMN07_PIN                   GPIO_Pin_2
/* BUTTON KEYBOARD COL */
#define COLUMN08_PORT                  GPIOB
#define COLUMN08_PIN                   GPIO_Pin_9
#define COLUMN09_PORT                  GPIOB
#define COLUMN09_PIN                   GPIO_Pin_7
#define COLUMN10_PORT                  GPIOB
#define COLUMN10_PIN                   GPIO_Pin_5
/* RESERVED KEYBOARD COL */
#define COLUMN11_PORT                  GPIOC
#define COLUMN11_PIN                   GPIO_Pin_7//GPIO_Pin_10
/* ASIX
PC15 PC1 PC3 PA1 - PA3 PA5 PA7 PC5
LEFT KEYBOARD
PC14 PC00 PC02 - PA00 PA02 PA04
BUTTON
PB09 PB07 PB05 - PB03 PC12 PC10
*/
#define ROW_LINE                    0x01
#define RCC_APB2Periph_ROW_GPIO    (RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOC|RCC_APB2Periph_GPIOB)
/* RIGHT KEYBOARD ROW */
#define ROW01_PORT                  GPIOA
#define ROW01_PIN                   GPIO_Pin_3
#define ROW02_PORT                  GPIOA
#define ROW02_PIN                   GPIO_Pin_5
#define ROW03_PORT                  GPIOA
#define ROW03_PIN                   GPIO_Pin_7
#define ROW04_PORT                  GPIOC
#define ROW04_PIN                   GPIO_Pin_5
/* LEFT KEYBOARD ROW */
#define ROW05_PORT                  GPIOA
#define ROW05_PIN                   GPIO_Pin_0//GPIO_Pin_11
#define ROW06_PORT                  GPIOA//GPIOC
#define ROW06_PIN                   GPIO_Pin_2//GPIO_Pin_12
#define ROW07_PORT                  GPIOA//GPIOB
#define ROW07_PIN                   GPIO_Pin_4//GPIO_Pin_13
/* BUTTON KEYBOARD ROW */
#define ROW08_PORT                  GPIOB//GPIOC
#define ROW08_PIN                   GPIO_Pin_3//GPIO_Pin_6
#define ROW09_PORT                  GPIOC//GPIOB
#define ROW09_PIN                   GPIO_Pin_12//GPIO_Pin_8
#define ROW10_PORT                  GPIOC
#define ROW10_PIN                   GPIO_Pin_10//GPIO_Pin_7
/* RESERCED KEYBOARD ROW */
#define ROW11_PORT                  GPIOB
#define ROW11_PIN                   GPIO_Pin_10

/*  */
#if defined(STM32L1XX_MD) 

#define         ID1          (0x1FF80050)
#define         ID2          (0x1FF80054)
#define         ID3          (0x1FF80064)

#else /*STM32F1x*/
#define         ID1          (0x1FFFF7E8)
#define         ID2          (0x1FFFF7EC)
#define         ID3          (0x1FFFF7F0)
#endif
	void Set_System(void);
	void EXTI_Configuration(void);
	void USB_Interrupts_Config(void);
	void Set_USBClock(void);
	void Leave_LowPowerMode(void);
	//void USB_Cable_Config(FunctionalState NewState);
	void Get_SerialNum(void);
	//static void IntToUnicode(uint32_t value, uint8_t *pbuf, uint8_t len);


	void KeyBoard_Config(void);
	uint16_t KEYBOARD_GPIO(uint8_t statues);
	uint32_t KeyBoard_Scan(void);
#ifdef __cplusplus
}
#endif
#endif
